package com.guochenglang.www.util.connect;


import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 连接池的配置类
 *
 * @author 郭程朗
 */
public class Config {
    /**
     * 初始链接个数
     */
    private static int init;
    /**
     * 最大链接个数
     */
    private static int max;
    /**
     * url
     */
    private static String url = null;
    /**
     * username
     */
    private static String username = null;
    /**
     * password
     */
    private static String password = null;
    /**
     * 等待时间
     */
    private static Long waitTime = null;

    //静态代码块执行初始化
    static {
        Properties prop = new Properties();
        //读取properties文件
        InputStream inputStream = Config.class.getClassLoader().getResourceAsStream("jdbc.properties");
        try {
            prop.load(inputStream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        //对初始值进行赋值
        url = prop.getProperty("url");
        username = prop.getProperty("username");
        password = prop.getProperty("password");
        init = Integer.parseInt(prop.getProperty("init"));
        max = Integer.parseInt(prop.getProperty("max"));
        waitTime = Long.parseLong(prop.getProperty("waitTime"));


    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        Config.password = password;
    }

    public int getInit() {
        return init;
    }

    public void setInit(int init) {
        Config.init = init;
    }

    public int getMax() {
        return max;
    }

    public void setMax(int max) {
        Config.max = max;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        Config.url = url;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        Config.username = username;
    }

    public Config() {
    }

    public Long getWaitTime() {
        return waitTime;
    }

    public void setWaitTime(Long waitTime) {
        Config.waitTime = waitTime;
    }

    public Config(int init, int max) {
        Config.init = init;
        Config.max = max;
    }
}
